package com.zeros.mysplashtwo.http;

import android.content.Context;

import com.zeros.mysplashtwo.utils.NetCheckUtilTwo;
import com.zeros.mysplashtwo.utils.ZlogUtilTwo;
import com.zhy.autolayout.utils.L;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2017/12/22.
 */

public abstract class MyRxSubscribe<T> implements Observer<T> {

    private Context mContext;

    public MyRxSubscribe(Context mContext) {
        this.mContext = mContext;
    }

    protected abstract void _onNext(T t);
    protected abstract void _onError(String message);

    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(T t) {
        _onNext(t);
    }

    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
        try {
            if (!NetCheckUtilTwo.isConnected(mContext)) {
                ZlogUtilTwo.e("RxSubscribe====>网络不可用!");
                _onError("网络错误，请检查网络！");
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        _onError(e.getMessage());
    }

    @Override
    public void onComplete() {

    }
}
